import request,{post} from '../utils/request'
import baseUrl from '../config/config'
export function absUrl(url){
    if(!url){
        return url;
    }
    if(url.indexOf('://')!=-1){
        return url
    }
    return baseUrl + url
}
export function firgure(){
    return request({
        url:'/api/figure',
        method:'get'
    })
}

export function myfirgure(){
    return request({
        url:'/api/myfigure',
        method:'get'
    })
}


export function banners(){
    return request({
        url:'/api/banners',
        method:'get'
    })
}

export function intro(){
    return request({
        url:'/api/intro',
        method:'get'
    })
}

export function ranklist(query){
    return request({
        url:'/api/ranklist',
        method:'get',
        params:query
    })
}

export function getAreas(){
    return request({
        url:'/api/areas',
        method:'get'
    })
}

export function timeInfo(){
    return request({
        url:'/api/timeInfo',
        method:'get'
    })
}
export function ww(w){
    return w > 9 ? w:0+''+w
}

export function uploadImg(file){
    let param = new FormData()  // 创建form对象
    param.append('modal_file', file, file.name)  // 通过append向form对象添加数据
    return post('/util/upload',param,{
        headers: {'Content-Type': 'multipart/form-data'}
    })
}
export function uploadBlob(blob){
    var file = new File([blob], 'msr-' + (new Date).toISOString().replace(/:|\./g, '-') + '.wav', {
        type: 'audio/wav'
    });

    // create FormData
    var formData = new FormData();
    formData.append('audio-filename', file.name);
    formData.append('audio-blob', file);
    return post('/util/uploadBlob',formData,{
        headers: {'Content-Type': 'multipart/form-data'}
    })
}

export function applyActivity(data){
    return request({
        url:'/api/apply',
        method:'post',
        data
    })    
}

export function playerlist(query){
    return request({
        url:'/api/playerlist',
        method:'get',
        params:query
    })
}

export function fetchPlayer(query){
    return request({
        url:'/api/playerDetail',
        method:'get',
        params:query
    })
}

export function fetchSelfApplyInfo(){
    return request({
        url:'/api/selfApplyInfo',
        method:'get'
    })
}

export function fetchSelfApplyInfoForEdit(){
    return request({
        url:'/api/selfApplyInfoForEdit',
        method:'get'
    })
}

export function votePlayer(query){
    return request({
        url:'/api/vote',
        method:'get',
        params:query
    })
}
//incViewedCount

export function incViewedCount(query){
    return request({
        url:'/api/incViewedCount',
        method:'get',
        params:query
    })
}
let u = navigator.userAgent;
export function isAndroid(){
    return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
} 

export function isIOS(){
    return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) || !!u.match(/^ua;tag=app;/); //ios终端
} 
var ua = navigator.userAgent;
var ms = ua.match(/tag=(\w+);?/);
let ua_tag = env,ua_account = envAccount 
if (ms) {
    ua_tag = ms[1] || '';
    ms = ua.match(/account=(\w+)/);
    if(ms){
        ua_account = ms[1] || '';
    }    
}
export function isInLiGuApp(){    
    return ua_tag == 'app'
}
export function getLiguAppCount(){
    return ua_account;
}
export function hasLogin(){
    return !!ua_account
}
